package com.lg.mengbase.testBottonTab;

import android.support.v4.app.Fragment;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

import com.lg.baselibrary.activity.BaseBottomFrameLayoutTabActivity;
import com.lg.baselibrary.widget.TabItemView;
import com.lg.mengbase.R;
import com.lg.mengbase.TestKeyboardListenerAty;
import com.lg.mengbase.testBottonTab.fragment.TabFragment1;
import com.lg.mengbase.testBottonTab.fragment.TabFragment2;
import com.lg.mengbase.testBottonTab.fragment.TabFragment3;
import com.lg.mengbase.testBottonTab.fragment.TabFragment4;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ligang on 2017/5/29.
 * description：Tabs+FrameLayout+Fragment(CenterView)
 */

public class TestBottomTabViewActivity extends BaseBottomFrameLayoutTabActivity{
    @Override
    protected List<TabItemView> getTabViews() {
        List<TabItemView> tabItemViews = new ArrayList<>();
        tabItemViews.add(new TabItemView(this,"首页", R.color.bottom_tab_text_def,
                R.color.bottom_tab_text_selected,R.mipmap.bottom_feed_normal,R.mipmap.bottom_feed_press));
        tabItemViews.add(new TabItemView(this,"热榜",R.color.bottom_tab_text_def,
                R.color.bottom_tab_text_selected,R.mipmap.bottom_hotrank_normal,R.mipmap.bottom_hotrank_press));
        tabItemViews.add(new TabItemView(this,"发现",R.color.bottom_tab_text_def,
                R.color.bottom_tab_text_selected,R.mipmap.bottom_discovery_normal,R.mipmap.bottom_discovery_press));
        tabItemViews.add(new TabItemView(this,"我",R.color.bottom_tab_text_def,
                R.color.bottom_tab_text_selected,R.mipmap.bottom_my_normal,R.mipmap.bottom_my_press));
        return tabItemViews;
    }

    @Override
    protected List<Fragment> getFragments() {
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new TabFragment1());
        fragments.add(new TabFragment2());
        fragments.add(new TabFragment3());
        fragments.add(new TabFragment4());
        return fragments;
    }
    private Animation centerAnimation;
    @Override
    protected void setCenterView() {
        super.setCenterView();
        centerAnimation = AnimationUtils.loadAnimation(this,R.anim.anim_bottom_centerview_press);
        centerAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
//                String s = null;
//                int length = s.length();
                startActivity(TestKeyboardListenerAty.class);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        setCenterView(R.layout.v_bottom_tab_centerview, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.startAnimation(centerAnimation);
            }
        });
    }
    private boolean isLogin; //模拟登录
    @Override
    public boolean onInterceptTabItemSelect(int position) {
        isLogin = !isLogin;
        if(position == fragments.size()-1){
            if(isLogin){
                return false;
            }
            Toast.makeText(this, "请先登录", Toast.LENGTH_SHORT).show();
            return true;
        }
        if(position == 2){ //取消位置为2的tab上的消息提示
            hideTipCount(2);
        }
        if(position == 1){
            hideTipImageView(1);
        }
        return super.onInterceptTabItemSelect(position);
    }

    @Override
    protected void initData() {
        showTipCount(2,2);
        showTipImageView(3,R.mipmap.send_msg_failure);
        showTipImageView(1,R.mipmap.point,-3,-7,11,11);
    }
}
